#!/bin/sh

queuecpu=20
queueio=10

echo $queuecpu
echo $queueio
make clean;
make;

#fcfs
echo "FCFS"
if [ ! -d "task2" ]; then
	mkdir task2
else
	rm -rf task2/*
fi

for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho $queuecpu $queueio 100000 0 0 >> task2/output_task2_fcfs
#		sleep 2
done

grep 'Average CLR =' task2/output_task2_fcfs | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/clr.fcfs

grep 'Running time =' task2/output_task2_fcfs | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/running.fcfs


echo "LCFS"
for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho $queuecpu $queueio 100000 0 1 >> task2/output_task2_lcfs
#		sleep 2
done

grep 'Average CLR =' task2/output_task2_lcfs | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/clr.lcfs

grep 'Running time =' task2/output_task2_lcfs | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/running.lcfs


echo "SJF"
for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho $queuecpu $queueio 100000 0 2 >> task2/output_task2_sjf
#		sleep 2
done


grep 'Average CLR =' task2/output_task2_sjf | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/clr.sjf

grep 'Running time =' task2/output_task2_sjf | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/running.sjf

if [ ! -d "task2/prioritynp" ]; then
	mkdir task2/prioritynp
else
	rm -rf task2/prioritynp/*
fi

echo "Priority-NP"
for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho $queuecpu $queueio 100000 0 3 >> task2/prioritynp/output_task2_prioritynp
#		sleep 2
done

grep 'Average CLR for queue one =' task2/prioritynp/output_task2_prioritynp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/prioritynp/clr_queue0.prioritynp
grep 'Average CLR for queue two =' task2/prioritynp/output_task2_prioritynp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/prioritynp/clr_queue1.prioritynp
grep 'Average CLR for queue three =' task2/prioritynp/output_task2_prioritynp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/prioritynp/clr_queue2.prioritynp
grep 'Average CLR for queue four =' task2/prioritynp/output_task2_prioritynp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/prioritynp/clr_queue3.prioritynp

grep 'Average CLR =' task2/prioritynp/output_task2_prioritynp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/prioritynp/clr.prioritynp

grep 'Running time =' task2/prioritynp/output_task2_prioritynp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/prioritynp/running.prioritynp

if [ ! -d "task2/priorityp" ]; then
	mkdir task2/priorityp
else
	rm -rf task2/priority/*
fi

echo "Priority-P"
for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho $queuecpu $queueio 100000 0 4 >> task2/priorityp/output_task2_priorityp
#		sleep 2
done

grep 'Average CLR for queue one =' task2/priorityp/output_task2_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/priorityp/clr_queue0.priorityp
grep 'Average CLR for queue two =' task2/priorityp/output_task2_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/priorityp/clr_queue1.priorityp
grep 'Average CLR for queue three =' task2/priorityp/output_task2_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/priorityp/clr_queue2.priorityp
grep 'Average CLR for queue four =' task2/priorityp/output_task2_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/priorityp/clr_queue3.priorityp

grep 'Average CLR =' task2/priorityp/output_task2_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/priorityp/clr.priorityp

grep 'Running time =' task2/priorityp/output_task2_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task2/priorityp/running.priorityp
